<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <title>travel</title>
  </head>
  <body>
    <div id="app"></div>
    <div id="allmap"></div>
    <!-- built files will be auto injected -->
    <script src="https://api.map.baidu.com/api?v=3.0&ak=AUZ12sYK7BhLd8VowWgoQincKka0XpGD"></script>
    <script>
      var map = new BMap.Map("allmap");
      var point = new BMap.Point(116.331398,39.897445);
      map.centerAndZoom(point,12);

      function myFun(result){
        var cityName = result.name;
        var newCity = '';
        map.setCenter(cityName);
        if (cityName.indexOf('市')) {
          newCity = cityName.slice(0, cityName.length-1)
        }
        localStorage.setItem('city', newCity)
      }
      var myCity = new BMap.LocalCity();
      myCity.get(myFun); 

    </script>
  </body>
</html>
